package com.ecommerce.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * Swagger配置类
 * 原生：/swagger-ui.html
 * 美化:/doc.html
 */
@Configuration
@EnableSwagger2
public class SwaggerConfig {

    /**
     * 配置Swagger的描述信息
     */
    public ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("e-commerce-micro-service")
                .description("e-commerce-springcloud-service")
                .contact(new Contact("Vincent", "www.ecommerce.com", "wen@163.com"))
                .version("1.0")
                .build();
    }

    /**
     * Swagger 实例Bean是Docket, 所以通过配置Docket 实例来配置Swagger
     */
    @Bean
    public Docket docket() {
        return new Docket(DocumentationType.SWAGGER_2)
                // 展示在页面上的自定义工程描述信息
                .apiInfo(apiInfo())
                // 选择展示哪些接口
                .select()
                // 只要com.ecommerce包内的才去展示
                .apis(RequestHandlerSelectors.basePackage("com.ecommerce"))
                .paths(PathSelectors.any())
                .build();
    }

}
